﻿using DirectSell.BLL.EFBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DirectSell.Model.User;
using Direct.IDAL.User.Jurisdiction;
using System.Collections;
using System.Data.SqlClient;
using Dapper;

namespace DirectSell.BLL.User.Jurisdiction
{
    /// <summary>
    /// 会员激活
    /// </summary>
    public class ActivationService:UserService
    {
        #region 日志记录
        /// <summary>
        /// 日志记录文件名
        /// </summary>
        protected override string LogFile
        {
            get
            {
                return base.LogFile;
            }
        }
        #endregion

        #region 初始化数据
        protected IActivationRepository _activation { get; set; }
        public ActivationService(IActivationRepository activation)
        {
            this._activation = activation;
        }
        #endregion

        #region 操作
        /// <summary>
        /// 操作入口
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="param"></param>
        /// <returns></returns>
        protected async override Task<UserRespCode> OperationAsync<T>(T param)
        {
            var reqModel = param as ActivationReq;

            if (param == null)
            {
                return UserRespCode.传入参数不正确;
            }
            await LogAsync(reqModel);

            if(!await _activation.CheckStatus(reqModel.UserId))
            {
                return UserRespCode.重复提交;
            }
            var conditions = new DynamicParameters();
            conditions.Add("@userid", reqModel.UserId);
            conditions.Add("@ActivatedId", reqModel.ActivationId);
            var result =  _activation.ExecProc("Activated_Settlement", conditions);
            if (!result)
            {
                return UserRespCode.失败;
            }
            return UserRespCode.成功;
        }
        #endregion
    }
}
